//
//  BargainsCell.m
//  ProjectForA
//
//  Created by 靖哥哥 on 14/11/20.
//  Copyright (c) 2014年 hmengwei. All rights reserved.
//

#import "BargainsCell.h"
#import "RecommendModel.h"
#import "UIImageView+WebCache.h"

@implementation BargainsCell



- (void)dealloc
{
    [_yuanQi release];
    [_shiChang release];
    [_bargainImage release];
    [_bargainLabel release];
    [_barGoLabel release];
    [_barPriceLabel release];
    [_barMoneyLabel release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.bargainImage = [[UIImageView alloc] init];
        _bargainImage.backgroundColor = [UIColor whiteColor];
        _bargainImage.layer.cornerRadius = 10;
        _bargainImage.layer.masksToBounds = YES;
        [self addSubview:_bargainImage];
        [_bargainImage release];
        
        self.bargainLabel = [[UILabel alloc] init];
        _bargainLabel.backgroundColor = [UIColor whiteColor];
        _bargainLabel.numberOfLines = 0;
        [self addSubview:_bargainLabel];
        [_bargainLabel release];
        
        self.barGoLabel = [[UILabel alloc] init];
        _barGoLabel.backgroundColor = [UIColor whiteColor];
        [_barGoLabel setAlpha:.6f];
        [self addSubview:_barGoLabel];
        [_barGoLabel release];
        
        self.shiChang = [[UILabel alloc] init];
        _shiChang.backgroundColor = [UIColor whiteColor];
        _shiChang.alpha = .6f;
        [self addSubview:_shiChang];
        [_shiChang release];
        
        self.yuanQi = [[UILabel alloc] init];
        _yuanQi.textColor = [UIColor redColor];
        [self addSubview:_yuanQi];
        [_yuanQi release];
        
        self.barPriceLabel = [[UILabel alloc] init];
        _barPriceLabel.backgroundColor = [UIColor whiteColor];
        _barPriceLabel.alpha = .6f;
        [self addSubview:_barPriceLabel];
        [_barPriceLabel release];
        
        self.barMoneyLabel = [[UILabel alloc] init];
        _barMoneyLabel.backgroundColor = [UIColor whiteColor];
        _barMoneyLabel.textColor = [UIColor redColor];
        _barMoneyLabel.font = [UIFont systemFontOfSize:25];
        [self addSubview:_barMoneyLabel];
        [_barMoneyLabel release];
        
        
        [self addObserver:self forKeyPath:@"model" options:NSKeyValueObservingOptionNew context:nil];
        
    }
    return self;
}

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    if ([keyPath isEqualToString:@"model"]) {
        
        [self.bargainImage setImageWithURL:[NSURL URLWithString:self.model.cover]];
        self.bargainLabel.text = self.model.title;
        self.barGoLabel.text = self.model.depart_place;
        NSString *str = [NSString stringWithFormat:@"%ld", self.model.market_price];
        NSString *strr = [NSString stringWithFormat:@"%ld", self.model.min_price];
        self.barPriceLabel.text = str;
        self.barMoneyLabel.text = strr;
        self.shiChang.text = @"市场价:";
        self.yuanQi.text = @"元起";
    }
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    _bargainImage.frame = CGRectMake(0, 0, self.frame.size.width / 3, 140);
    _bargainLabel.frame = CGRectMake(self.bargainImage.frame.origin.x + self.bargainImage.frame.size.width + 5, 0, 230, 50);
    
    _barGoLabel.frame = CGRectMake(self.bargainImage.frame.origin.x + self.bargainImage.frame.size.width + 5, self.bargainLabel.frame.origin.y + self.bargainLabel.frame.size.height + 3, 230, 20);
    _shiChang.frame = CGRectMake(self.bargainImage.frame.origin.x + self.bargainImage.frame.size.width + 5, self.barGoLabel.frame.origin.y + self.barGoLabel.frame.size.height + 3, 60, 20);
    _barPriceLabel.frame = CGRectMake(self.shiChang.frame.origin.x + self.shiChang.frame.size.width, self.barGoLabel.frame.origin.y + self.barGoLabel.frame.size.height + 3, 170, 20);
    _barMoneyLabel.frame = CGRectMake(self.bargainImage.frame.origin.x + self.bargainImage.frame.size.width + 5, self.barPriceLabel.frame.origin.y +self.barPriceLabel.frame.size.height + 3, 70, 40);
    _yuanQi.frame = CGRectMake(self.barMoneyLabel.frame.origin.x + self.barMoneyLabel.frame.size.width, self.barPriceLabel.frame.origin.y +self.barPriceLabel.frame.size.height + 3, 160, 40);
}


- (void)awakeFromNib {
    
    
    
    
    
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
